package com.diaohw.module.system.controller;


import com.diaohw.module.system.obj.dto.SysMenuDTO;
import com.diaohw.module.system.obj.query.SysMenuQuery;
import com.diaohw.module.system.obj.vo.RouteVO;
import com.diaohw.module.system.obj.vo.SysMenuVO;
import com.diaohw.module.system.service.SysMenuService;
import com.diaohw.platform.common.obj.page.PageResultVo;
import com.diaohw.platform.common.validator.InsertGroup;
import com.diaohw.platform.common.validator.UpdateGroup;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜单控制层
 *
 * @author Ray.Hao
 * @since 2020/11/06
 */
@Tag(name = "菜单接口（新）")
@RestController
@RequestMapping("/api/v1/menus")
@Slf4j
public class SysMenuController {

    @Resource
    private SysMenuService service;


    @PostMapping
    @Operation(summary = "新增")
    public SysMenuVO create(@RequestBody @Validated(InsertGroup.class) SysMenuDTO data) {
        return service.create(data);
    }

    @PutMapping("{id}")
    @Operation(summary = "更新")
    public SysMenuVO update(@PathVariable("id") String id, @RequestBody @Validated(UpdateGroup.class) SysMenuDTO data) {
        return service.update(id, data);
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除")
    public Boolean delete(@PathVariable("id") String id) {
        return service.delete(id);
    }

    @GetMapping("/{id}")
    @Operation(summary = "依据ID查看信息")
    public SysMenuVO detail(@PathVariable("id") String id) {
        return service.detail(id);
    }

    @GetMapping
    @Operation(summary = "查询列表")
    public List<SysMenuVO> all(SysMenuQuery query) {
        return service.findByList(query);
    }


    @GetMapping("/page")
    @Operation(summary = "分页查看")
    public PageResultVo<SysMenuVO> page(SysMenuQuery query) {
        return service.findByPage(query);
    }


    @Operation(summary = "菜单路由列表")
    @GetMapping("/routes")
    public List<RouteVO> routes() {
        return service.routes();
    }


}

